package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Signin;
import cn.wolfcode.trip.base.service.ISigninService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/signins")
public class SigninController {
    @Autowired
    private ISigninService signinService;
    /*
    * 签到的接口
    * 资源:/signins
    * 动作:POST
    * 参数:userId=?&days=?&time=?
    * */
    @PostMapping
    public Object signin(Signin signin){
        JSONResult result = new JSONResult();
        try{
            signinService.save(signin);
            result.setData(signin);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    /*
     * 某个用户今天的签到信息
     * 资源:/signins/{userId}
     * 动作:GET
     * 参数:userId=?
     * */
    @GetMapping("/{userId}")
    public Object getToday(@PathVariable Long userId){

        return signinService.getToday(userId);
    }
    /*
     * 获取某个用户的历史签到信息
     * 资源:/signins/{userId}/signins
     * 动作:GET
     * 参数:userId=?
     * */
    @GetMapping("/{userId}/signins")
    public Object getHistory(@PathVariable Long userId){
        return signinService.getHistory(userId);
    }
    @GetMapping("/{userId}/days")
    public Object getHistoryDays(@PathVariable Long userId){
        return signinService.getHistoryDays(userId);
    }
}
